package com.newer.controller.sys;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.newer.pojo.sys.Pickstandard;
import com.newer.service.sys.iter.PickstandardService;
import com.newer.utils.sys.BootstrapDataTable;
import com.newer.utils.sys.Conditions;
import com.newer.utils.sys.MsgUtil;

@RequestMapping("pickstandard")
@Controller
public class PickstandardController {
	@Autowired
	private PickstandardService pickstandardService;
	
	@RequestMapping("list")
	@ResponseBody
	public BootstrapDataTable list(BootstrapDataTable dataTable,Conditions conditions) {
		System.out.println();
		BootstrapDataTable table = pickstandardService.selectPickstandardByExample(dataTable, conditions);
		return table;
	}
	@RequestMapping("view")
	public String view(){
		return "sys/pickstandard/pickstandard";
	}
	/**
	 * 跳转到添加页面
	 * @return
	 */
	@RequestMapping("add")
	public String addTo(){
		return"sys/pickstandard/pickstandard_add";
	}
	/**
	 * 添加收派标准
	 * @param Pickstandard
	 * @return
	 */
	@RequestMapping("addPickstandard")
	public @ResponseBody MsgUtil addPickstandard(Pickstandard pickstandard){
		try {
			pickstandardService.addPickstandard(pickstandard);
			return MsgUtil.result(true, "添加完成");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return MsgUtil.result(false, "添加失败");
		}
	
	}
	
	/**
	 * 分页显示数据
	 * @param dataTable
	 * @param conditions
	 * @return
	 */
	@RequestMapping(value= {"pickstandardList"})
	public @ResponseBody BootstrapDataTable regionList(BootstrapDataTable dataTable,Conditions conditions) {
		BootstrapDataTable pickstandardByExample =pickstandardService.selectPickstandardByExample(dataTable, conditions);
		return pickstandardByExample;
	}
	
	/**
	 * 批量删除
	 * @param Ids
	 * @return
	 */
	@RequestMapping("batchdelete/{ids}")
	public @ResponseBody MsgUtil toDeleteIds(@PathVariable("ids") String Ids) {
		try{
			pickstandardService.deletePickstandardByIds(Ids);
			 return MsgUtil.result(true, "删除成功！");
		}catch(Exception e){
			return MsgUtil.result(false , "删除失败！");
		}
	}
		/**
		 * 删除，修改删除状态为1
		 * @param pickstandard
		 * @return
		 */
	@RequestMapping("delete")
	@ResponseBody
	public MsgUtil deletePickstandard(Integer id){
		try {
			pickstandardService.delete(id);
			return MsgUtil.result(true, "删除成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return MsgUtil.result(false, "删除失败！");
		}
	}
	/**
	 * 检查部门是否存在
	 * @param standardName
	 * @return
	 */
	@RequestMapping("checkStandardName")
	public @ResponseBody Map<String,Boolean>checkStandardName(String standardName){
		Map<String,Boolean>selectStandardName=pickstandardService.selectPickstandardByStandardName(standardName);
		return selectStandardName;
	}
	
	/**
	 * 根据id查询
	 * @param id
	 * @param request
	 * @return
	 */
	@RequestMapping("selectPickstandardById/{id}")
	public String selectPickstandardById(@PathVariable("id")Integer id,HttpServletRequest request){
		request.setAttribute("pickstandard", pickstandardService.selectPickstandardById(id));
		return "sys/pickstandard/pickstandard_edit";
	}
	
	/**
	 * 修改
	 * @param pickstandard
	 * @return
	 */
	@RequestMapping("update")
	public @ResponseBody MsgUtil update(Pickstandard pickstandard){
		try {
			pickstandardService.updatePickstandardByPrimarykey(pickstandard);
			return MsgUtil.result(true, "修改成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return MsgUtil.result(false, "修改失败");
		}
	}
	}
